#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/6/16 0016 22:22
# @Author  : wzy
# @Site    : 
# @File    : operate_config.py
# @Software: PyCharm
import json
from Util.operate_pathUrll import pathinfo
base = pathinfo

class OperateJson():
    def read_json(self,file_name):
        if file_name == None:
            file_path = base.get_project_baseUrl()+"/Config/user_data.json"
        else:
            file_path = base.get_project_baseUrl()+"/Config/"+file_name
        with open(file_path,encoding='UTF-8') as f:
            data = json.load(f)
        return data

    def get_json_value(self,key,file_name=None):
        data = self.read_json(file_name)
        return data.get(key)

    def write_json_value(self,data,file_name=None):
        data = json.dumps(data)
        if file_name ==None:
            path = base.get_project_baseUrl()+"/Config/cookie.json"
            print(path)
        else:
            path = base.get_project_baseUrl()+"/Config/"+file_name
        with open(path,"w") as f:
            f.write(data)
            print("写入完成")
operateJson = OperateJson()
if __name__ == '__main__':
    data = {
        "app": {
            "cc22c": "cc22cc"
        }
    }
    operateJson.write_json_value(data,'test.json')
